<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.dingpeikeji.quickdeer.core.common.utils.IdGen"%>
<%@page import="com.dingpeikeji.quickdeer.modules.base.web.FSysController"%>
<%@page import="com.dingpeikeji.quickdeer.core.common.utils.CookieUtils"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>微信绑定</title>
    <%
	String token = IdGen.uuid();
	session.setAttribute("token", token);
	%>
    <link href="${ctxStatic }/index/login/css/w_binding.css" rel="stylesheet">
    <script src="${ctxStatic}/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function(){
		var keyVal2= "${sessionScope.mes}";
		if(keyVal2.length!=0){  
			alert(keyVal2);
			window.location.href = "${pageContext.request.contextPath }/login.jsp";
		}  
		 $("#btn").attr("disabled", true); 
		$("input[name='loginName']").blur(function(){
			//获取输入的值
			var $value=$(this).val();
			if($value.length==11){  
			$.post("${ctxFront}/sms/checkTel","mobile="+$value,function(d){
				//alert(d);
				if(d==0){//手机已被注册,不需要输入密码
					$('#newPassword').hide();
					$('#confirmNewPassword').hide();
					$('#btn').removeAttr('disabled');
					$("#btn").click(function(){
						$.post('${ctxFront}/sms/send', {"phone":$value,"type":0},function(data) {
							if (data != 'success') {
								alert(data);
							} 
						});
					});
					$('#subBtn').removeAttr('disabled');
				}else if(d==2){//手机号格式不对
					$('#newPassword').hide();
					$('#confirmNewPassword').hide();
					$("#subBtn").attr("disabled", true); 
				}else if(d==1){//手机未注册,需输入密码
					$('#newPassword').show();
					$('#confirmNewPassword').show();
					$("input[name='confirmNewPassword']").blur(function(){
						//获取输入的值
						var $password1=$("#newPassword").val();
						var $password2=$(this).val();
						if($password1.length!=0 && $password2.length!=0){  
							$.post("${ctxFront}/sms/checkPassword",{"password1":$password1,"password2":$password2},function(d){
								if(d==0){
									alert("两次输入的密码不一致");
									$("#subBtn").attr("disabled", true); 
								}else if(d==1){
									alert("6-16位数字和字母的组合");
									/* $("#confirmTip").html("<font color='red'>6-16位数字和字母的组合</font>"); */
									$("#subBtn").attr("disabled", true); 
								}else if(d==2){
									$("#confirmTip").html("");
									$('#subBtn').removeAttr('disabled')
								}
							});
						}
					});
					$('#btn').removeAttr('disabled');
					$("#btn").click(function(){
						$.post('${ctxFront}/sms/send', {"phone":$value,"type":0},function(data) {
							if (data != 'success') {
								alert(data);
							} 
						});
					});
					$('#subBtn').removeAttr('disabled');
				}
			});
			}
		});
	});
	var countdown = 60;
	function settime(obj) {
		if (countdown == 0) {
			obj.removeAttribute("disabled");
			obj.value = "获取短信验证码";
			countdown = 60;
			return;
		} else {
			obj.setAttribute("disabled", true);
			obj.value = "重新发送(" + countdown + ")";
			countdown--;
		}
		setTimeout(function() {
			settime(obj)
		}, 1000)
	};
	function subRegisterForm() {
		if($("#validateCode").val().length!=4||$("#loginName").val().length!=11){
			return false;
		}
			$('#bindWxForm').submit();
	}
</script>    
</head><%session.removeAttribute("mes");%>
<body>
<div class="head">
    <a href="${ctxFront }/index"><img src="${ctxStatic }/index/images/logo.png"></a>
</div>
	<form action="${ctxFront }/info/bindWx" method="post" id="bindWxForm">
	<input type="hidden" name="unionid" value="${user.unionid}">
		<div class="w_binding">
			<div class="w_binding_1">
				<span><img src="${user.userInfo.headimgurl }"
					style="width: 60px; height: 60px"></span> <span class="dg_user">尊敬的微信用户：${user.userInfo.nickname }</span>
				<span class="dg_name"></span>
				<br><font  color="red" size="3">${messages }</font>
			</div>
			<span class="w_binding_2">为了给您更好的服务，请关联一下霞客账号，便于您下次快速登录</span>
			<div class="phone_nume">
				<input class="dg_nume" type="text" name="loginName" id="loginName" placeholder="&nbsp;&nbsp;手机号码">
				<span id="mobilTip"></span>
			</div>
			<div class="phone_nume">
				<input class="dg_nume" type="password" name="newPassword" id="newPassword" placeholder="&nbsp;&nbsp;你还未注册过本网站,请输入密码,便于下次登陆,6-16位字母加数字" style='display:none;'>
				<span id="newPasswordTip"></span>
			</div>
			<div class="phone_nume">
				<input class="dg_nume" type="password" name="confirmNewPassword" id="confirmNewPassword" placeholder="&nbsp;&nbsp;请再次输入密码" style='display:none;'>
				<span id="confirmTip"></span>
			</div>
			<div class="phon" style="padding-bottom: 50px">
				<input class="dg_iden " maxlength="4" name="validateCode" id="validateCode" type="text" placeholder="&nbsp;&nbsp;手机验证码">
				<input type="text" id="btn" class="dg_obtain" value="点击获取验证码" onclick="settime(this)"/> 
			</div>
			<div style="padding-bottom: 20px">
			<input type="button" class="dg_garee" id="subBtn" onclick="subRegisterForm()" value="同意协议并绑定">
			</div>
			<a class="agreement" href="${pageContext.request.contextPath }/webInfo.jsp?id=xz" target="_blank">《霞客约车服务协议》</a>
		</div>
	</form>
</body>
</html>